package com.kupurui.asteacher.ui;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.android.frame.ui.BaseActivity;
import com.kupurui.asteacher.R;

import butterknife.Bind;

/**
 * Created by pmj on 2017/2/4.
 * 网页显示aty
 */
public class WebLoadUrlAty extends BaseActivity {
    @Bind(R.id.m_toolbar)
    Toolbar mToolbar;
    @Bind(R.id.webview)
    WebView webview;
    @Bind(R.id.pb_progress)
    ProgressBar pbProgress;

    private String url;

    @Override
    public int getLayoutId() {
        return R.layout.webview_aty;
    }

    @Override
    public void initData() {
        initToolbar(mToolbar, "");
        url = getIntent().getStringExtra("url");

        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setAppCacheEnabled(true);
        webview.getSettings().setAllowFileAccess(true);
        //设置支持缩放
        webview.getSettings().setBuiltInZoomControls(true);
        if (url.startsWith("http"))
            webview.loadUrl(url);
        else
            webview.loadUrl("http://" + url);

        webview.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                mToolbar.setTitle(title);
            }

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    //网页加载完成
                    pbProgress.setVisibility(View.GONE);
                } else {
                    //加载中
                    pbProgress.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }
        });

        webview.setWebViewClient(new WebViewClient());

    }

    @Override
    public void requestData() {

    }

//
//    private class MyWebChromeClient extends WebViewClient{
//
//    }
}
